package com.amado.course42Socket.tcp.chatSystem;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.CharBuffer;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author wangyulong
 * @version 1.5.0
 * @date 2020/3/7 19:00
 */
public class Client {
    public static void main(String[] args) throws IOException {
        Socket serverSocket = new Socket("localhost",8080);
        PrintWriter printWriter = new PrintWriter(serverSocket.getOutputStream(),true);
        Scanner scanner = new Scanner(System.in);
        startSocket(serverSocket);
        java.util.Scanner sc = new java.util.Scanner(System.in);

        while(true) {
            printWriter.println("1#temp");
            System.out.println("1、选择聊天的用户 q!退出");
            String line = sc.nextLine();
            if("s!".equals(line)){

            }else  if("q!".equals(line)){
                break;
            }else{
                while(true){
                    System.out.println("输入聊天的内容，q!表示退出");
                    String content = sc.nextLine();
                    if("q!".equals(content)){
                        break;
                    }
                    printWriter.println("2#"+line+"#"+content);
                }
            }

        }
    }
    public static void startSocket(Socket socket){
        new Thread(()->{
            try {
                BufferedReader  lineNumberReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                while(true){
                    System.out.println(lineNumberReader.readLine());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }).start();
    }
}
